﻿Imports System.Collections.Generic
Public Class PhieuDAO
    'phuong thuc lay danh sach dua vao ma mon

    Public Shared Function laydanhsachphieu(ByVal phieu As String) As List(Of CPhieu)
        Dim kq As List(Of CPhieu) = New List(Of CPhieu)
        Dim str As String = String.Format("SELECT * from NhanVien where MaPhieu='{0}' ", phieu)
        Dim dt As DataTable = CKetNoi.ExecQuery(str)
        For Each i As DataRow In dt.Rows
            Dim p As New CPhieu
            p.MaPhieu = i("MaPhieu")
            p.NgayTaoPhieu = i("NgayTaoPhieu")

            p.TinhTien = i("TinhTien")
           
            kq.Add(p)
        Next
        Return kq
    End Function
    Public Shared Function Insert(ByVal b As CPhieu) As Integer
        Dim sql As String = String.Format("INSERT INTO Phieu(NgayTaoPhieu,TinhTien) VALUES('{0}',{1})", b.NgayTaoPhieu, b.TinhTien)
        Return CKetNoi.ExecuteScalar(sql)

    End Function
    Public Shared Function Delete(ByVal mphieu As String) As Integer
        Dim sql As String = String.Format("Delete from Phieu where MaPhieu='{0}'", mphieu)
        Return CKetNoi.ExecnonQuery(sql)

    End Function
    Public Shared Function Update(ByVal b As CPhieu) As Integer
        Dim sql As String = String.Format("Update Phieu set NgayTaoPhieu={0},MaBan='{1}',TinhTien={2}", b.NgayTaoPhieu, b.TinhTien)
        Return CKetNoi.ExecnonQuery(sql)

    End Function
    Public Shared Function getId() As Integer
        Dim kq As Integer = 0
        Dim str As String = String.Format("SELECT MAX(MaPhieu) as MaxId from Phieu")
        Dim dt As DataTable = CKetNoi.ExecQuery(str)
        For Each i As DataRow In dt.Rows

            kq = i("MaxId")
           
        Next
        Return kq + 1
    End Function
End Class
